var cartDatas = localStorage.getItem("cartDatas");
var cartListDatas = cartDatas ? JSON.parse(cartDatas) : [];
if (cartListDatas.length == 0) {
    console.log(123)
} else {
    src1 = `<ul>
    <li><img src="${ cartListDatas.dz }" width="30px"><span>${ cartListDatas.cpjs }</span></li>
    </ul>`
    $('.kongk').append(src1)
    $('.s2').text($('.kongk').children().length - 1)
    $('.stp-right').text(cartListDatas.jg)
    $('.s5').text($('.kongk').children().length - 1)
}

$('.gwc').click(function () {
    var cartDatas = localStorage.getItem("cartDatas");
    var cartListDatas = cartDatas ? JSON.parse(cartDatas) : [];
    var src2 = $('.Gui-smallPicture img').attr('src')
    var src3 = $('.Gui-span11-box').text()
    var src4 = $('.Gui-shop-price').text()
    var src5 = localStorage.getItem('indexs')
    var src = {
        "id": src5,
        "dz": src2,
        "cpjs": src3,
        "jg": src4
    }
    console.log(cartListDatas)
    var src1 = ''
    //  console.log(cartListDatas[1])
    src1 = `<ul>
    <li><img src="${ cartListDatas.dz }" width="30px"><span>${ cartListDatas.cpjs }</span></li>
    </ul>`
    $('.kongk').append(src1)
    if (cartListDatas.id == src.id) {
        return cartListDatas.id == src.id
    }
    // });
    // 如果条件存在--只增加数量即可
    if (cartListDatas) {
        for (let i = 0; i < cartListDatas.length; i++) {
            if (cartListDatas[i].goods_id == src.goods_id) {
                cartListDatas[i].buy_num += src.buy_num;
            }
        }
    } else {
        cartListDatas.push(src);
    }
    // console.log(cartDatas)
    localStorage.setItem("cartDatas", JSON.stringify(src));
    if ($('.kongk').children().length > 1) {
        $('.kongk').children().eq(0).css({
            display: 'none',
        })
        $('.s2').text($('.kongk').children().length - 1)
    }

})